<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="cancle();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            <p id="titleConten"></p>
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">

        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info" style="margin-left:5%;width:40%; background-color: green" onclick="save()">提交
        </div>
        <div class="aui-btn aui-btn-info" style="margin-left:5%;width:40%;background-color: red" onclick="cancle()">关闭
        </div>
        <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;">
            <table class="table" style='width:100%;' id="table">
                <thead>
                    <tr
                        style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 12px;font-weight: bold;">
                        <td algin='center' style="width:8%">
                            <input name='main' type='checkbox' id="allboxs" onclick="allcheck()" />
                        </td>
                        <td algin='center'>序号</td>
                        <td algin='center'>人员编码</td>
                        <td algin='center'>人员名称</td>
                        <td algin='center'>工号</td>
                        <td algin='center'>班组</td>
                    </tr>
                </thead>
                <tbody id="employeeDataHtml">
                </tbody>
            </table>
        </div>
    </div>


</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var equipUniqueId = "";

    //初始化
    apiready = function () {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //上岗
        if (api.pageParam.flag == 1) {
            document.getElementById("titleConten").innerHTML = "产线人员上岗";

        } else if (api.pageParam.flag == 2) {
            document.getElementById("titleConten").innerHTML = "产线人员离岗";
        }

        //查询记录  上岗则查这个班组未上岗的人员。离岗查询已上岗的人员
        doSearch();
    }

    //查询上岗信息
    function doSearch() {
        var workCellCode = "";
        //是否按工位上岗查询：0否，1是
        var cjFlag = api.pageParam.cjFlag;
        if ("1" == cjFlag) {
            workCellCode = api.pageParam.workCellCode;
        }
        var proddate = $("#prodDate").val();
        var teamCode = $("#teamCode").val();
        var shiftCode = $("#shiftCode").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblySearchEmployeeData";
        var data = {
            values: {
                workCenterCode: api.pageParam.workCenterCode,
                workCellCode: workCellCode,
                proddate: api.pageParam.proddate,
                teamCode: api.pageParam.teamCode,
                shiftCode: api.pageParam.shiftCode,
                flag: api.pageParam.flag,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    //班組賦值
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        console.log(JSON.stringify(list[i]));
                        console.log(list[i].empCode);
                        html += "<tr style='text-align: center;color: black;font-size: 10px;background-color: #F5F5F5;'>";
                        html += "<td><input name='sub' type='checkbox' /></td>";
                        html += "<td name='index'>" + (i + 1) + "</td>";
                        html += "<td name='empCode'>" + list[i].empCode + "</td>";
                        html += "<td name='empName'>" + list[i].empName + "</td>";
                        html += "<td name='empNo'>" + list[i].empNo + "</td>";
                        html += "<td name='teamName'>" + list[i].teamName + "</td>";
                        html += "</tr>";
                    }
                    console.log(html);
                    $api.html($api.byId("employeeDataHtml"), html);
                } else {
                    $api.html($api.byId("employeeDataHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    function allcheck() {
        var nn = $("#allboxs").is(":checked"); //判断th中的checkbox是否被选中，如果被选中则nn为true，反之为false
        if (nn == true) {
            var namebox = $("input[name^='sub']");  //获取name值为boxs的所有input
            for (i = 0; i < namebox.length; i++) {
                namebox[i].checked = true;    //js操作选中checkbox
            }
        }
        if (nn == false) {
            var namebox = $("input[name^='sub']");
            for (i = 0; i < namebox.length; i++) {
                namebox[i].checked = false;
            }
        }
    }

    //上岗/离岗保存
    function save() {

        //选中数据
        var check = $("input[name='sub']:checked");
        var count = 0;
        var empNo = "";
        var empNoStr = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            empNo = row.find("[name='empNo']").html();
            count++;

            if (empNoStr == "") {
                empNoStr += empNo;
            } else {
                empNoStr += "," + empNo;
            }
        });

        if (count == 0) {
            api.toast({
                msg: "请选择至少一条表格数据",
                duration: 3000
            });
            return;
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyTakeQuitPostZSSave";
        var data = {
            values: {
                proddate: api.pageParam.proddate,
                workCenterCode: api.pageParam.workCenterCode,
                workCellCode: api.pageParam.workCellCode,
                teamCode: api.pageParam.teamCode,
                shiftCode: api.pageParam.shiftCode,
                opCode: api.pageParam.opCode,
                flag: api.pageParam.flag,
                empNoStr: empNoStr,
                sgFlag: api.pageParam.sgFlag,//上岗标识：0刷卡，1勾选
                cjFlag: api.pageParam.cjFlag,//是否按工位上岗查询：0否，1是
                un: un
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功!",
                        duration: 3000
                    });

                    //返回上级页面
                    cancle();
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    //取消,返回上一级
    function cancle() {
        api.closeWin({});
        api.execScript({
            name: 'productionSglg',
            script: 'refresh()'
        });
    }

</script>

</html>